# Monarc makefile

CC  = gcc
AS  = nasm
LD  = ld
AR  = ar
SED = sed
PL = perl

INCL = \
	-Iinclude \
	-I../libc/include \
	-I../libsupc++/include \
#	-I../../../include \

DEFINES = \
#	-D__DEBUG \

OPT_OR_DEBUG = \
	-O

OC_OPT = -Wall $(OPT_OR_DEBUG) -mno-stack-arg-probe -ffreestanding -nostartfiles -nodefaultlibs -nostdlib -nostdinc $(INCL) $(DEFINES)
OCC_OPT = -Wall $(OPT_OR_DEBUG) -mno-stack-arg-probe -nostartfiles -fno-builtin -nodefaultlibs -nostdlib -nostdinc $(INCL) $(DEFINES)
#OCC_OPT = -Wall $(OPT_OR_DEBUG) -mno-stack-arg-probe -nostartfiles -nodefaultlibs -nostdlib -nostdinc $(INCL) $(DEFINES)

MALLOC_OPTS = -Wall $(OPT_OR_DEBUG) -mno-stack-arg-probe -ffreestanding -nostartfiles -nodefaultlibs -nostdlib -nostdinc $(INCL) -include malloc-fix.h
KMALLOC_OPTS = -Wall $(OPT_OR_DEBUG) -mno-stack-arg-probe -ffreestanding -nostartfiles -nodefaultlibs -nostdlib -nostdinc $(INCL) -include malloc-fix.h -DKERNEL

MKDIR = mkdir
CP = cp
CAT = cat
RM = rm -f

MODULES = \
	crt0.o \
	c_startup.o \
	exit.o \
	errno.o \
	abort.o \
	syscall.o \
	malloc.o \
	atomic.o \
	spinlock.o \
	mutex.o \
	mutex_asm.o \
	gthr-monarc.o \
	udivmoddi3.o \
	mem.o \
	qsort.o \
	new.o \
	sbrk.o \
	QList.o \

all: libsys.a

clean:
	$(RM) *.o libsys.a

libsys.a: $(MODULES)
	ar cru $@ $?
		
malloc.o: malloc.c include/malloc-fix.h
	$(CC) $(MALLOC_OPTS) -c $< -o $@

%.o : %.asm
	$(AS) -fwin32 $< -o $@

%.o: %.c %.h
	$(CC) $(OC_OPT) -c $< -o $@

%.o: %.cc %.h
	$(CC) $(OCC_OPT) -c $< -o $@

%.o: %.cc
	$(CC) $(OCC_OPT) -c $< -o $@

%.o: %.c
	$(CC) $(OC_OPT) -c $< -o $@

